from Monitor.NetworkMonitor import NetworkDelayMonitor,NetworkMonitor,MonitorType,NetworkBandWidthMonitor
from containernet.node import DockerSta
from OSM_Mininet_wifi.node import OSMDockerStaion,OSMDockerCloud
from containernet.cli import CLI
from containernet.term import makeTerm
from mininet.log import info, setLogLevel,output
from mn_wifi.mobility import Mobility
from mininet.node import Controller
from OSM_Mininet_wifi.net import OSM_Mininet_wifi
from mn_wifi.net import OVSKernelAP

setLogLevel('info')
net = OSM_Mininet_wifi(controller=Controller,autoAssociation=False)


net.addAccessPoint(**{'type': 'bs', 'name': 'bs0', 'location': [28.19867803255195, 112.9633913041471], 'position': [-394, 222, 0], 'ssid': 'ssid-bs0', 'ip': '10.0.0.1/8', 'ip6': '2001:0:0:0:0:0:0:1/64', 'mac': '00:00:00:00:00:01', 'range': 500, 'failMode': 'standalone'})
net.addAccessPoint(**{'type': 'bs', 'name': 'bs1', 'location': [28.196903255457872, 112.96974706656331], 'position': [229, 25, 0], 'ssid': 'ssid-bs1', 'ip': '10.0.0.2/8', 'ip6': '2001:0:0:0:0:0:0:2/64', 'mac': '00:00:00:00:00:02', 'range': 500, 'failMode': 'standalone'})
net.addDocker(**{'type': 'ec', 'name': 'ec0', 'location': [28.197564848658335, 112.97146368033285], 'position': [397, 99, 0], 'ip': '10.0.0.3/8', 'ip6': '2001:0:0:0:0:0:0:3/64', 'mac': '00:00:00:00:00:03', 'range': 500, 'dimage': 'ubuntu:test2', 'sysctls': {'net.ipv6.conf.all.disable_ipv6': '0'}},cls=OSMDockerCloud)
net.addDocker(**{'type': 'ec', 'name': 'ec1', 'location': [28.197527043442935, 112.96406078345173], 'position': [-328, 94, 0], 'ip': '10.0.0.4/8', 'ip6': '2001:0:0:0:0:0:0:4/64', 'mac': '00:00:00:00:00:04', 'range': 500, 'dimage': 'ubuntu:test2', 'sysctls': {'net.ipv6.conf.all.disable_ipv6': '0'}},cls=OSMDockerCloud)
net.addStation(**{'type': 'mp', 'name': 'mp0', 'location': ['28.196014823860214,112.97086286551351', '28.196052629610584,112.96326684958332'], 'position': '338,-74,0', 'ip': '10.0.0.5/8', 'ip6': '2001:0:0:0:0:0:0:5/64', 'mac': '00:00:00:00:00:05', 'range': 500, 'speed': 50, 'dimage': 'ubuntu:test2', 'sysctls': {'net.ipv6.conf.all.disable_ipv6': '0'}},cls=OSMDockerStaion)
net.OSM_Mobility_For_ConfigurationData(**{'NodeMobilityConfig': {'speed': 50, 'coord': ['339,-103,0', '341,7,0', '359,9,0', '360,1,0', '359,-177,0', '356,-177,0', '339,-176,0', '325,-175,0', '307,-173,0', '297,-173,0', '295,-176,0', '295,-187,0', '280,-186,0', '243,-183,0', '186,-177,0', '142,-172,0', '86,-165,0', '71,-164,0', '-18,-156,0', '-128,-146,0', '-286,-139,0', '-345,-133,0', '-406,-132,0', '-407,-132,0'], 'distance': 1095.4914526349653}, 'node': 'mp0'})
net.addStation(**{'type': 'mp', 'name': 'mp1', 'location': ['28.200891655240333,112.96517658240192', '28.198339852626837,112.97077703482503'], 'position': '-219,468,0', 'ip': '10.0.0.6/8', 'ip6': '2001:0:0:0:0:0:0:6/64', 'mac': '00:00:00:00:00:06', 'range': 500, 'speed': 50, 'dimage': 'ubuntu:test2', 'sysctls': {'net.ipv6.conf.all.disable_ipv6': '0'}},cls=OSMDockerStaion)
net.OSM_Mobility_For_ConfigurationData(**{'NodeMobilityConfig': {'speed': 50, 'coord': ['-104,443,0', '-106,421,0', '-106,388,0', '-21,384,0', '16,393,0', '85,393,0', '84,399,0', '176,401,0', '171,387,0', '239,385,0', '239,414,0', '247,430,0', '321,428,0', '325,371,0', '328,281,0', '329,255,0', '330,215,0', '330,204,0', '330,176,0'], 'distance': 802.5918845826775}, 'node': 'mp1'})
net.startController(**{'controller': 'None', 'name': 'c', 'number': 1, 'ip': '127.0.0.1', 'port': 6653, 'protocol': 'tcp', 'app': 'simple_switch'})
net.configureWifiNodes()
net.addLink(**{'type': 'nl', 'node1': 'bs0', 'node2': 'ec1', 'delay': '20ms', 'bw': 10, 'jitter': '0ms', 'loss': 0})
net.addLink(**{'type': 'nl', 'node1': 'bs1', 'node2': 'ec0', 'delay': '40ms', 'bw': 10, 'jitter': '0ms', 'loss': 0})
net.OSM_Mobility_Setting(**{'mobility_start_time': 1, 'reverse': 1, 'ac_method': 'ssf', 'mob_rep': 1, 'mobility_mode': 'quickly'})
net.start()
thread_list = []
t=NetworkDelayMonitor('mp0', 'ec0', net, monitor_type= {'delay'}).start(data_storage_Directory='/home/kylin/Desktop/PythonProject/OSM_Mininet_WIFI/Mininet_WIFI/Network_Topology/Network_Topology_20230530230022979210.json',**{'period': 60}).thread_
thread_list.append(t)
t=NetworkDelayMonitor('mp0', 'ec1', net, monitor_type= {'delay'}).start(data_storage_Directory='/home/kylin/Desktop/PythonProject/OSM_Mininet_WIFI/Mininet_WIFI/Network_Topology/Network_Topology_20230530230022979210.json',**{'period': 60}).thread_
thread_list.append(t)
t=NetworkDelayMonitor('mp1', 'ec0', net, monitor_type= {'delay'}).start(data_storage_Directory='/home/kylin/Desktop/PythonProject/OSM_Mininet_WIFI/Mininet_WIFI/Network_Topology/Network_Topology_20230530230022979210.json',**{'period': 60}).thread_
thread_list.append(t)
t=NetworkDelayMonitor('mp1', 'ec1', net, monitor_type= {'delay'}).start(data_storage_Directory='/home/kylin/Desktop/PythonProject/OSM_Mininet_WIFI/Mininet_WIFI/Network_Topology/Network_Topology_20230530230022979210.json',**{'period': 60}).thread_
thread_list.append(t)
for td in thread_list: td.join()
net.OSM_Experiment_Ended(data_storage_Directory='/home/kylin/Desktop/PythonProject/OSM_Mininet_WIFI/Mininet_WIFI/Network_Topology/Network_Topology_20230530230022979210.json')
net.stop()
